/*
 Copyright (c) Whitemice Consulting, 2007, 2008, 2009
 Adam Tauno Williams <awilliam@whitemice.org>
 License: MIT/X11

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using Gtk;
using GLib;
using System.Reflection;
using System.Runtime.InteropServices;
using Whitemice.ZOGI;

/*
namespace Whitemice.ZOGI.GtkWidgets
{
  public class Db4oStoreMapEntry {
    private string                          title;
    private System.Reflection.PropertyInfo   info;
    
    public Db4oStoreMapEntry(string title, System.Type type, string property)
    {
      this.title = title;
      this.info = type.GetProperty(property);
    }
    
    public string Title 
    {
      get { return title; }
    }
    
    public System.Type ValueType
    {
      get { return info.GetType(); }
    }
    
    public object GetValue(object obj)
    {
      return info.GetValue(obj, null);
    }
  }

  public class Db4oStore : GLib.Object, TreeModelImplementor
  {
    IObjectSet                   data;
    private Gtk.TreeModelAdapter pAdapter;
    public readonly System.Int32 Stamp;
    ArrayList<Db4oStoreMapEntry> map;
    
    /* ctor 
    public Db4oStore(ICollection<Db4oStoreMapEntry> map,
                     Db4objects.Db4o.IObjectSet objectSet) : base()
    {
      this.map = map;
      this.data = objectSet;
			System.Random RandomStampGen = new System.Random ();
			this.Stamp = RandomStampGen.Next (System.Int32.MinValue, System.Int32.MaxValue);
			this.pAdapter = new Gtk.TreeModelAdapter (this);
    }
    
		public Gtk.TreeModelAdapter Adapter {
			get { return pAdapter; }
		}
		
		public object GetRowAtPath (Gtk.TreePath path) {
			switch (path.Indices.Length) {
			case 0:
				return null;
			case 1:
				return (data[path.Indices[0]]);
			default:
				// Model is list-only; there are no child iters
				throw (new System.ArgumentOutOfRangeException ("path"));
			}
		}
		
		public Gtk.TreeModelFlags Flags {
			get { return Gtk.TreeModelFlags.ListOnly;
				// return Gtk.TreeModelFlags.ItersPersist;
			}
		}
		
		public System.Int32 NColumns {
			get { return this.map.Count; }
		}
		
		public GLib.GType GetColumnType (int col)
		{
		  return ((GLib.GType)(map[col].ValueType));
		}
  } /* end class TaskStore 
} /* end namespace */
